import { tabbarArr } from '../router';
const install = (Vue, vm) => {
  let vue_global = Vue.config.globalProperties;
  let u = {};
  u.router = (path = '', query = {}, pageState = 1) => {
    let routerSlide = pageState === -1 && !path ? 0 : 1;
    let store_router = vue_global.$store_router;
    console.log(
      $core.arrFindIndex(tabbarArr, 'name', path),
      $core.deepClone(store_router.state).routerIndex
    );
    if (
      path &&
      $core.arrFindIndex(tabbarArr, 'name', path) !== -1 &&
      $core.deepClone(store_router.state).routerIndex !== -1
    ) {
      routerSlide =
        $core.arrFindIndex(tabbarArr, 'name', path) <
        $core.deepClone(store_router.state).routerIndex
          ? 0
          : 1;
    }
    store_router.setState('routerSlide', routerSlide);
    setTimeout(() => {
      store_router.setState('routerSlide', 0);
    }, 750);
    if (pageState === -1 && !path) {
      vue_global.$router.back();
    } else if (pageState === 0) {
      vue_global.$router.replace({
        path: '/' + path,
        query: query || {},
      });
    } else {
      vue_global.$router.push({
        path: '/' + path,
        query: query || {},
      });
    }
  };
  u.$clearRouterAlive = (key = '') => {
    let complementArr = $core
        .arr2set(vue_global.$store_router.state.keepAlive, key.split(','))
        .diff(),
      oldRouterState = vue_global.$store_router.state.keepAlive;
    routerState.stateDefault.setState('keepAlive', complementArr);
    setTimeout(() => {
      routerState.stateDefault.setState('keepAlive', oldRouterState);
    }, 750);
  };

  u = $core.deepMerge($core, u);
  u.apiCore = $apiCore;

  Vue.config.globalProperties.$core = u;
};

export default {
  install,
};
